.pc = * "Keyboard Routines"

keyboard_bits:
    .fill 8,0

// call once a frame to update keyboard_bits
scan_keyboard:
{
    .for (var i = 0; i < 8; i++)
    {
        lda #[255 - [1<<i]]
        sta $dc00
        lda $dc01
        sta keyboard_bits+i
    }

    rts
}

//////////////////////////////

.macro TestKey(row, col)
{
    lda keyboard_bits+row
    and #[1<<col]
}

.macro TestWKey() { :TestKey(1,1) }
.macro TestAKey() { :TestKey(1,2) }
.macro TestSKey() { :TestKey(1,5) }
.macro TestDKey() { :TestKey(2,2) }
.macro Test0Key() { :TestKey(4,3) }
